package gps.implementationAPI;

import gps.Colors;
import gps.Direction;
import gps.GPSRun;
import gps.api.GPSState;
import gps.states.SquareState;

public class GPSProblemHeu3Implementation extends GPSGenericProblemImplementation {
	
	public GPSProblemHeu3Implementation() {
		super();
	}

	@Override
	public Integer getHValue(GPSState state) {
		int ret = 0;
		
		for(int i = 0 ; i < GPSRun.N ; i++){
			for (int j = 0 ; j < GPSRun.N ; j++){
				SquareState ss = state.getElementState(i, j);
				
				if(ss == null){
					continue;
				}
				
				if(ss.isUniform()) {
					if (ss.getFirstColor() == Colors.BLACK){
						ret += 3;
					}
				} else {
					if (ss.getDirection() == Direction.HORIZONTAL) {
						if (ss.getFirstColor() == Colors.WHITE && state.getBlank().x == i-1) {
							ret += 1;
						} else if (ss.getSndColor() == Colors.WHITE && state.getBlank().x == i+1) {
							ret += 1;
						} else {
							ret+=2;
						}
					} else if (ss.getDirection() == Direction.VERTICAL) {
						if (ss.getFirstColor() == Colors.WHITE && state.getBlank().y == j+1) {
							ret += 1;
						} else if (ss.getSndColor() == Colors.WHITE && state.getBlank().y == j-1) {
							ret += 1;
						} else {
							ret+=2;
						}
					}
				}
			}
		}
		
		return ret;
	}

}
